package com.luckynote.common.user;

import com.luckynote.common.base.result.ExecuteResult;
import com.luckynote.common.base.result.MultiEntryResult;
import com.luckynote.common.base.util.BeanUtil;
import com.luckynote.common.user.dto.UserDTO;
import com.luckynote.common.user.query.UserQuery;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
 * <pre>
 * *********************************************
 * Copyright LUCKY-NOTE.
 * All rights reserved.
 * ****************************************************
 *  Version       Date         Author            Desc
 *    v1.0       2019/6/29      bingo           用户相关Controller
 * ****************************************************
 * </pre>
 */
@RequestMapping("/common/user")
@RestController
public class UserController {

    private Logger logger = LoggerFactory.getLogger(this.getClass());

    @Autowired
    HttpServletRequest request;

    @Autowired
    private UserService userService;

    @RequestMapping("saveOrUpdate")
    public ExecuteResult saveOrUpdate(UserDTO userDTO){
        logger.info("UserController.saveOrUpdate receive param : [{}]",BeanUtil.toJson(userDTO));
        return userService.saveOrUpdate(userDTO);
    }

    @RequestMapping("/delete/{userId}")
    public ExecuteResult delete(@PathVariable("userId") String userId){
        logger.info("UserController.delete receive param : [{}]",userId);
        return userService.delete(userId);
    }

    @RequestMapping("/list")
    public MultiEntryResult<UserDTO> list(UserQuery userQuery){
        logger.info("UserController.list receive param : [{}]",BeanUtil.toJson(userQuery));
        return userService.list(userQuery);
    }

}
